package com.shengqiang.cloud.ups.controller;

import com.shengqiang.cloud.ups.common.model.JsonResult;
import com.shengqiang.cloud.ups.dao.modal.UpmsPermission;
import com.shengqiang.cloud.ups.service.UpmsMenuWebService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/23.
 * 菜单管理controller
 */
@Controller
@RequestMapping(value = "sysMenu")
public class SysMenuController {

    @Autowired
    private UpmsMenuWebService service;

    @RequestMapping(value = "toSysMenu",method = {RequestMethod.POST,RequestMethod.GET})
    public String toSysMenu(){
        return "/systemSetting/menu";
    }

    @ResponseBody
    @RequestMapping(value = "menuTree",method = {RequestMethod.GET,RequestMethod.POST})
    public List<UpmsPermission> selectMenuTree(@RequestParam Map<String,Object> params){
        return service.loadParentMenus(params);
    }

    @RequiresPermissions(value = "upms:sysSetting:menu:add")
    @ResponseBody
    @RequestMapping(value = "addMenuNode",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult<UpmsPermission> addMenuTreeNode(UpmsPermission upmsPermission){
        return service.addMenuTreeNode(upmsPermission);
    }

    @RequiresPermissions(value = "upms:sysSetting:menu:list")
    @ResponseBody
    @RequestMapping(value = "selectMenus",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult<List<UpmsPermission>> selectMenus(@RequestParam Map<String,Object> params){
        return service.selectMemus(params);
    }

    @RequiresPermissions(value = "upms:sysSetting:menu:edit")
    @ResponseBody
    @RequestMapping(value = "updateMenu",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult updateMenu(UpmsPermission upmsPermission){
        return service.updateMenu(upmsPermission);
    }

    @RequiresPermissions(value = "upms:sysSetting:menu:delete")
    @ResponseBody
    @RequestMapping(value = "deleteMenu",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult deleteMenu(int id){
        return service.deleteMenuById(id);
    }
}
